<%@ page language="java" contentType="text/html; charset=UTF-8" pageEncoding="UTF-8"%>
<%@ taglib prefix="c" uri="http://java.sun.com/jsp/jstl/core"%>
<%
	String path = request.getContextPath();
	String basePath = request.getScheme() + "://" + request.getServerName() + ":" + request.getServerPort()
			+ path + "/";
%>
<!DOCTYPE html>
<html>
<head>
<meta charset="UTF-8">
<title>管理员管理</title>
<meta http-equiv="X-UA-Compatible" content="IE=edge">
<meta name="viewport" content="width=device-width, initial-scale=1">
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<meta name="keywords" content="Modern Responsive web template, Bootstrap Web Templates, Flat Web Templates, Andriod Compatible web template, 
Smartphone Compatible web template, free webdesigns for Nokia, Samsung, LG, SonyErricsson, Motorola web design" />
<script type="application/x-javascript"> addEventListener("load", function() { setTimeout(hideURLbar, 0); }, false); function hideURLbar(){ window.scrollTo(0,1); } </script>
 <!-- Bootstrap Core CSS -->
<link rel="stylesheet" type="text/css" href="${pageContext.request.contextPath }/css/bootstrap.css">
<!-- Custom CSS -->
<link href="${pageContext.request.contextPath }/css/style1.css" rel='stylesheet' type='text/css' />
<link rel="stylesheet" type="text/css" href="http://www.jq22.com/jquery/font-awesome.4.6.0.css"> 
<!-- jQuery -->
<script src="${pageContext.request.contextPath }/js/jquery-1.11.0.js"></script>

<!---//webfonts--->  
<!-- Bootstrap Core JavaScript -->
<script src="${pageContext.request.contextPath }/js/bootstrap.js"></script>
    <script type="text/javascript">
    	 /*全选或全不选*/
			//1.页面加载
			$(function(){
				//2.获取下面的复选框并将其选中状态设置跟编码的前端复选框保持一致
				$("#select").click(function(){
					 //atrr方法与JQ的版本有关，在1.8.3以下有关
					//$("tbody input[class='selectOne']").attr("checked",this.checked);
					$("tbody input[class='selectOne']").prop("checked",this.checked);
					
				});
			});
			
			/*全选删除*/
			function jjj(){
				var pList = "";
	            $("[name='all']").each(function () {
	                if ($(this).is(':checked')) {
	                    pList += $(this).val() + ",";
	                }
	            });
	            //去除最后的，
	           pList=pList.substr(0,pList.length-1);
	           var ids = pList;
	           if(pList==""){
	           	alert("请选择");
	           }else{
	           	var y = confirm("您确定要删除选择的项吗?");
	           	if(y){
	           		$.post(
	           		     "<%=basePath%>admin/deleteadmins.html",
	           		     {"ids":ids},
	           		     function (data) {
							alert("删除成功!");
							location.href="<%=basePath%>admin/admin.html";
						}
	           		);
	           	}
	           }

			}
			
		</script>
</head>
<body>
<div id="wrapper">
    <jsp:include page="/WEB-INF/jsp/admin/common.jsp"></jsp:include>
    
        
        <!--搜索-->
        <div id="page-wrapper">
           <div class="row" style="background-color: wheat;">
           <div class="col-lg-5"></div>
           <form id="searchForm" action="${pageContext.request.contextPath }/admin/serachAdmin.html" method="post">
              <div class="col-lg-4" style="padding-top: 15px;">
               <div class="input-group">
                       
							<!--输入框-->
							<input type="text" class="form-control" id="word" name="word" value="${word }" placeholder="请输入账号..." >
							<span class="input-group-btn">
						<button class="btn btn-warning btn-sm" type="submit">
							搜索
						</button>
					</span>
					
						</div>
						
              </div>
              </form>
              <div class="col-md-2 navbar-right" style="padding-top: 15px;">
						
									<!--<span class="glyphicon glyphicon-edit"></span>-->
									<button class="btn btn-info btn-sm glyphicon glyphicon-plus" data-toggle="modal" data-target="#myModal2">
											添加
											</button>
								
					</div>
           </div>
        <div class="row">
        <div class="col-md-12">  
  	       <h3>管理员管理</h3>
  	        <div class="bs-example4" data-example-id="contextual-table">
  	        	
              <table class="table table-hover">
	             <caption><input type="checkbox" id="select">
	             	<a href="#" class="btn btn-danger btn-sm" onclick="jjj()">
									<span class="glyphicon glyphicon-trash"></span> 批量删除
								</a>
	             </input>
	             </caption>
					<thead>
						<tr>
							<th>序号</th>
							<th>账号</th>
							<th>是否授权</th>
							<th>操作</th>
							
						</tr>
					</thead>
						<tbody>
						<c:forEach var="admin" items="${adminList }" varStatus="status">
							<tr>
								<td><input type="checkbox" class="selectOne" value="${admin.id }" name="all"/><span id="" style="padding-left: 5px;">${status.count}</span></td>
								<td>${admin.adminname}</td>
								<td>${admin.admingrant==1?"是":"否" }</td>
								<td>
								<!--编辑-->
								<a href="javascript:void(0);" onclick="editadmin(${admin.id })">
									
									<button class="btn btn-info btn-sm glyphicon glyphicon-edit" data-toggle="modal" data-target="#myModal">
											编辑
											</button>
								</a>
								&nbsp;&nbsp;
								<!--删除-->							
								<a href="javascript:void(0);" onclick="deleteadmin(${admin.id })" class="btn btn-danger btn-sm">
									<span class="glyphicon glyphicon-trash"></span> 删除
								</a>
								
							</td>	
							</tr>
							</c:forEach>

						</tbody>
				</table>
				<!--此处插入分页-->
             </div>
            </div>
            </div>
            
            
      </div>
      <!-- /#page-wrapper -->
   </div>
   
   <!--添加弹出层-->
   <div class="update_modal">
		<!-- 模态框（Modal） -->
		<div class="modal fade" id="myModal2" tabindex="-1" role="dialog" aria-labelledby="myModal2Label" aria-hidden="true">
			<div class="modal-dialog">
				<div class="modal-content" style="background-color:#A6A6A6;">
					<div class="modal-header">
						<button type="button" class="close" data-dismiss="modal" aria-hidden="true">×
				</button>
				
				
				
						<h4 class="modal-title" id="myModal2Label">
					添加管理员
				</h4>
					
					<form class="form-horizontal" role="form" id="adminAdd" method="post">
	
						<div class="form-group">
							<label for="adminname" class="col-sm-2 control-label">账号</label>
							<div class="col-sm-4">
								<input type="text" class="form-control" id="adminname1" name="adminname">
							</div>
						</div>
						
						<div class="form-group">
							<label for="adminpassword" class="col-sm-2 control-label">密码</label>
							<div class="col-sm-4">
								<input type="text" class="form-control" id="adminpassword1" name="adminpassword">
							</div>
						</div>
						
						<div class="form-group">
							<label for="admingrant" class="col-sm-2 control-label">是否授权</label>
							<div class="col-sm-4">
								<!--<input type="text" class="form-control" id="petsex" name="petsex">-->
								<select id="admingrant1" name="admingrant">
									<option value="">--请选择--</option>
									<option value="1">是</option>
									<option value="0">否</option>
								</select>
							</div>
						</div>
					
					
					<div class="modal-footer">
						<button type="button" class="btn btn-default" data-dismiss="modal">关闭
				</button>
						<button type="button" class="btn btn-primary" onclick="addadmin()">
					确定
				</button>
				
				</form>
				
					</div>
				</div>
				<!-- /.modal-content -->
			</div>
			<!-- /.modal-dialog -->
		</div>
		<!-- /.modal -->
		</div>
		
		<!--编辑弹出层-->
		<div class="update_modal">
		<!-- 模态框（Modal） -->
		<div class="modal fade" id="myModal" tabindex="-1" role="dialog" aria-labelledby="myModalLabel" aria-hidden="true">
			<div class="modal-dialog">
				<div class="modal-content" style="background-color:#A6A6A6;">
					<div class="modal-header">
						<button type="button" class="close" data-dismiss="modal" aria-hidden="true">×
				</button>

						<h4 class="modal-title" id="myModalLabel">
					编辑
				</h4>
					
					<form class="form-horizontal" role="form" id="updateForm">
						
						<div class="form-group">
							
							<div class="col-sm-4">
								<input type="hidden" class="form-control" id="id" name="id" value="">
							</div>
						</div>
	
						<div class="form-group">
							<label for="adminname" class="col-sm-2 control-label">账号</label>
							<div class="col-sm-4">
								<input type="text" class="form-control" id="adminname" name="adminname" value="">
							</div>
						</div>
						
						<div class="form-group">
							<label for="adminpassword" class="col-sm-2 control-label">密码</label>
							<div class="col-sm-4">
								<!-- <input type="text" class="form-control" id="adminpassword" name="adminpassword" value=""> -->
								<span id="adminpassword" name="adminpassword"></span>
							</div>
						</div>
						
						<div class="form-group">
							<label for="admingrant" class="col-sm-2 control-label">是否授权</label>
							<div class="col-sm-4">
								<select id="admingrant" name="admingrant">
									<option value="">--请选择--</option>
									<option value="1">是</option>
									<option value="0">否</option>
								</select>
							</div>
						</div>			
				</form>
					</div>
					<div class="modal-footer">
						<button type="button" class="btn btn-default" data-dismiss="modal">关闭</button>
						<button type="button" class="btn btn-primary" onclick="updateAdmin()">
					提交更改
				</button>
				
				</div>
				<!-- /.modal-content -->
			</div>
			<!-- /.modal-dialog -->
		</div>
		<!-- /.modal -->
		</div>
    <!-- /#wrapper -->
<!-- Nav CSS -->
<link href="${pageContext.request.contextPath}/css/custom.css" rel="stylesheet">
<!-- Metis Menu Plugin JavaScript -->
<script src="${pageContext.request.contextPath}/js/metisMenu.min.js"></script>
<script src="${pageContext.request.contextPath}/js/custom.js"></script>

<script type="text/javascript">





/* 编辑页面信息回显 */

function editadmin(id){
	$.post(
		"<%=basePath%>admin/adminInfo.html",
		{"id":id},
		function (data) {
			$("#id").val(data.id);
			$("#adminname").val(data.adminname);
			$("#adminpassword").html(data.adminpassword);
			$("#admingrant").val(data.admingrant);	
			
		},
		"json"
	);
  }
  
/*修改用户信息  */
function updateAdmin() {
	$.post(
		"<%=basePath%>admin/updateadminByid.html",
		$("#updateForm").serialize(),
		function (data) {
			alert("更新成功");
			location.href="<%=basePath%>admin/admin.html";
		}
	);
}

/* 添加管理员 */
function addadmin() {
	$.post("<%=basePath%>admin/addadmin.html",
			$("#adminAdd").serialize(),
			function (data) {
				alert("添加成功");
				location.href="<%=basePath%>admin/admin.html";
			}
			);
}
/* 删除管理员 */
function deleteadmin(id) {
	var yes = confirm("您确定要删除吗?");
	if(yes){
		$.post("<%=basePath%>admin/deleteAdmin.html",
				{"id":id},
				function (data) {
					alert("删除成功!");
					location.href="<%=basePath%>admin/admin.html";
				});
	}
}

</script>

</body>
</html>